<?php

namespace app\common\model;

use think\Model;

class Bases extends Model
{
    //添加基地
    public function addBases($data){
        $validate = new \app\common\validate\Bases();
        if (!$validate->scene('add')->check($data)){
            return $validate->getError();
        }
        $result = $this->allowField(true)->save($data);
        if ($result){
            return 1;
        }else{
            return '添加基地失败';
        }

    }
    //删除基地
    public function deleteBases(){




    }
    //基地列表
    public function selectAll(){

    }

    //基地地图
    public function basesMap($id){
        $result = $this->where('id',$id)->field('longitude latitude')->find();

            return $result;

    }
    //基地修改
    public function updateBases($id,$data){
        $result = $this->where('id',$id)->update($data);
        if ($result){
            return 1;
        }else{
            return '修改失败';
        }

    }
    //修改权重
    public function weight(){
        $id = input('put.id');
        $weight = input('put.weight');
        $data =[
            'page' => input('put.page'),
            'size' => input('put.size'),
            'success' => false,
            'message' => "修改失败",

        ];
        $result = model('Bases')->where('id',$id)->update(['weight'=>$weight]);
        if ($result){
            $data['success'] = true;
            $data['message'] = '修改成功';

        }
        return json($data);
    }
}
